
import SwiftUI

struct MainView: View {
    @State var currentTab = "videoList"
    
    var body: some View {
        NavigationView {
            GeometryReader { geometry in
                VStack(spacing:0) {
                    GeometryReader { geo in
                        if currentTab == "videoList" {
                            VideoListView()
                        }
                        else if currentTab == "favorite" {
                            
                        }
                    }
                    HStack(spacing: 0) {
                        Group {
                            TabBarBtn(title: "首页", key: "videoList", currentTab: $currentTab)
                            TabBarBtn(title: "关注", key: "favorite", currentTab: $currentTab)
                            Image("btn_home_add75x49")
                            TabBarBtn(title: "消息", key: "message", currentTab: $currentTab)
                            TabBarBtn(title: "我", key: "profile", currentTab: $currentTab)
                        }
                        .foregroundColor(.white)
                        .frame(width: geometry.size.width/5)
                    }
                    .frame(width: geometry.size.width, height: geometry.size.height / 10)
                    .background(Color.black)
                }
            }
            .background(Color.black)
            .edgesIgnoringSafeArea(.vertical)
        }
    }
}

struct TabBarBtn: View {
    var title: String
    var key: String
    @Binding var currentTab: String
    var body: some View {
        Text(title)
            .opacity(self.currentTab == key ? 1 : 0.6)
            .onTapGesture{
                self.currentTab = key
            }
    }
}

struct MainView_Previews: PreviewProvider {
    static var previews: some View {
        MainView()
    }
}
